package com.springboot.framework.response;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;

@Setter
@Getter
public class ResponseResult<T> {
    private int code;
    private String msg;
    private String message;
    private T data;

    /**
     * 返回成功
     *
     * @param t 泛型
     * @return ResponseResult
     */
    public ResponseResult ok(T t){
        this.setCode(200);
        this.setMsg("成功");
        this.setMessage("成功");
        this.setData(t);
        return this;
    }

    /**
     * 返回成功不带数据
     * @return
     */
    public ResponseResult ok(){
        this.setCode(200);
        this.setMsg("成功");
        this.setMessage("成功");
        return this;
    }

    /**
     * 返回失败
     *
     * @param msg 消息
     * @return ResponseResult
     */
    public ResponseResult fail(String msg){
        this.setCode(10001);
        this.setMessage(msg);
        this.setMsg(msg);
        return this;
    }
}
